package com.qfmy.web.controller;

import com.qfmy.web.consts.Result;
import com.qfmy.web.entity.login.LoginUser;
import com.qfmy.web.service.LoginUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * @author: 廖志伟
 * @date: 2024-11-28
 * @description: 登录控制器
 */
@RestController
@SuppressWarnings("all")
public class LoginController {
    //注入登录用户服务
    @Resource
    private LoginUserService loginUserService;

    /**
     * 注册接口
     */
    @PostMapping("/login/register")
    public Result register( String username,  String password,  String phone) {
        //调用注册方法
        loginUserService.register(username, password, phone);
        //返回结果
        return Result.success(200,"注册成功" );
    }

    /**
     * 登录接口
     * @param loginUser
     * @return
     */
    @PostMapping("/login")
    public Result login(String username, String password) {
        //调用登录方法
        String token = loginUserService.login(username,password);
        //返回结果
        return Result.success(200,token);
    }

    @GetMapping("/user/info")
    public Result<LoginUser> userInfo() {
        //获取当前登录用户信息
        LoginUser loginUser =  loginUserService.getLoginUser();
        return Result.success(200,loginUser);
    }

    @PutMapping("/user/updateInfo")
    public Result updateInfo(@RequestBody LoginUser loginUser) {
        //更新用户信息
        loginUserService.updateById(loginUser);
        return Result.success(200,"更新成功");
    }





}
